<?php

class Kal_Timetables_Block_Manage_Timetables_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
	protected function _prepareForm()
	{
		$form = new Varien_Data_Form();
		$this->setForm($form);
		$fieldset = $form->addFieldset('timetables_form', array('legend'=>Mage::helper('timetables')->__('Post information')));
		
		$fieldset->addField('title', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Title'),
		  'class'     => 'required-entry',
		  'required'  => true,
		  'name'      => 'title',
		));
		
		$fieldset->addField('color', 'select', array(
		'label'     => Mage::helper('timetables')->__('Color'),
		'name'      => 'color',
		'values'    => array(
		  array('value' => 'blue',			'label' => Mage::helper('timetables')->__('blue'),),
		  array('value' => 'yellow',		'label' => Mage::helper('timetables')->__('yellow'),),
		  array('value' => 'brown',			'label' => Mage::helper('timetables')->__('brown'),),
		  array('value' => 'green',			'label' => Mage::helper('timetables')->__('green'),),
		  array('value' => 'purple',		'label' => Mage::helper('timetables')->__('purple'),),
		  array('value' => 'pink',			'label' => Mage::helper('timetables')->__('pink'),),
		  array('value' => 'orange',		'label' => Mage::helper('timetables')->__('orange'),),
		  array('value' => 'purple-dark',	'label' => Mage::helper('timetables')->__('purple-dark'),),
		  array('value' => 'red',			'label' => Mage::helper('timetables')->__('red'),),
		),
		));
		
		$fieldset->addField('priceall', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Off Peak'),
		  'name'      => 'priceall'
		));
		
		$fieldset->addField('pricecsp', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Peak'),
		  'name'      => 'pricecsp'
		));
		
		/*$fieldset->addField('nfile', 'image', array(
		  'label'     => Mage::helper('timetables')->__('Image'),
		  //'class'     => 'required-entry',
		  'required'  => false,
		  'name'      => 'nfile',
		));
		$fieldset->addField('identifier', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Identifier'),
		  'class'     => 'required-entry',
		  'required'  => true,
		  'name'      => 'identifier',
		  'class'     => 'validate-identifier',
		  'after_element_html' => '<span class="hint">(eg: domain.com/timetables/identifier)</span>',
		));*/
	  
	  	/**
         * Check is single store mode
         */
        if (!Mage::app()->isSingleStoreMode()) {
            $fieldset->addField('store_id', 'multiselect', array(
                'name'      => 'stores[]',
                'label'     => Mage::helper('cms')->__('Store View'),
                'title'     => Mage::helper('cms')->__('Store View'),
                'required'  => true,
                'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
            ));
        }
        
		
		$categories = array();
	  	$collection = Mage::getModel('timetables/cat')->getCollection()->setOrder('sort_order', 'asc');
		foreach ($collection as $cat) {
			$categories[] = ( array(
				'label' => (string)$cat->getTitle(),
				'value' => $cat->getCatId()
				));
		}
		
	  	$fieldset->addField('cat_id', 'select', array(
                'name'      => 'cats[]',
                'label'     => Mage::helper('timetables')->__('Category'),
                'title'     => Mage::helper('timetables')->__('Category'),
                'required'  => true,
                'values'    => $categories,
     	));
		
		$fieldset->addField('status', 'select', array(
		'label'     => Mage::helper('timetables')->__('Status'),
		'name'      => 'status',
		'values'    => array(
		  array(
			  'value'     => 1,
			  'label'     => Mage::helper('timetables')->__('Enabled'),
		  ),
		
		  array(
			  'value'     => 2,
			  'label'     => Mage::helper('timetables')->__('Disabled'),
		  ),
		  
		  /*array(
			  'value'     => 3,
			  'label'     => Mage::helper('timetables')->__('Hidden'),
		  ),*/
		),

		//'after_element_html' => '<span class="hint">(Hidden Pages will not show in the timetables but can still be accessed directly)</span>',
		));
	  			
		/*$fieldset->addField('forder', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Order'),
		  'class'     => 'required-entry',
		  'required'  => false,
		  'name'      => 'forder',
		));*/
/*		$fieldset->addField('comments', 'select', array(
		'label'     => Mage::helper('timetables')->__('Enable Comments'),
		'name'      => 'comments',
		'values'    => array(
		  array(
			  'value'     => 0,
			  'label'     => Mage::helper('timetables')->__('Enabled'),
		  ),
		
		  array(
			  'value'     => 1,
			  'label'     => Mage::helper('timetables')->__('Disabled'),
		  ),
		),
		//'after_element_html' => '<span class="hint">Disabling will close the post to new comments</span>',
		));*/

		$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
        $fieldset->addField('thedate', 'date', array(
            'name'   => 'thedate',
            'label'  => Mage::helper('catalog')->__('Start Date'),
            'title'  => Mage::helper('catalog')->__('Start Date'),
            'image'  => $this->getSkinUrl('images/grid-cal.gif'),
            'format'       => $dateFormatIso,
        ));
        
        $fieldset->addField('enddate', 'date', array(
            'name'   => 'enddate',
            'label'  => Mage::helper('catalog')->__('End Date'),
            'title'  => Mage::helper('catalog')->__('End Date'),
            'image'  => $this->getSkinUrl('images/grid-cal.gif'),
            'format'       => $dateFormatIso,
        ));
        
		/*$fieldset->addField('thedate', 'date', array(
		  'label'     => Mage::helper('timetables')->__('Date'),
		  'class'     => 'required-entry',
		  'required'  => true,
		  'name'      => 'thedate',
		));*/
		
        $fieldset->addField('weekloop', 'multiselect', array(
		'label'     => Mage::helper('timetables')->__('Loop On Each'),
		'name'      => 'weekloops[]',
		'values'    => array(
		  array('value' => '1',		'label' => Mage::helper('timetables')->__('Monday'),),
		  array('value' => '2',		'label' => Mage::helper('timetables')->__('Tuesday'),),
		  array('value' => '3',		'label' => Mage::helper('timetables')->__('Wednesday'),),
		  array('value' => '4',		'label' => Mage::helper('timetables')->__('Thursday'),),
		  array('value' => '5',		'label' => Mage::helper('timetables')->__('Friday'),),
		  array('value' => '6',		'label' => Mage::helper('timetables')->__('Saturday'),),
		  array('value' => '7',		'label' => Mage::helper('timetables')->__('Sunday'),),
		),
		'after_element_html' => '<span class="hint">(Save then continue select start time and end time)</span>',
		));
		
		
		$time_array = array(
		  	array('value'=>1, 'label'=>'00:00'),
array('value'=>2, 'label'=>'00:15'),
array('value'=>3, 'label'=>'00:30'),
array('value'=>4, 'label'=>'00:45'),
array('value'=>5, 'label'=>'01:00'),
array('value'=>6, 'label'=>'01:15'),
array('value'=>7, 'label'=>'01:30'),
array('value'=>8, 'label'=>'01:45'),
array('value'=>9, 'label'=>'02:00'),
array('value'=>10, 'label'=>'02:15'),
array('value'=>11, 'label'=>'02:30'),
array('value'=>12, 'label'=>'02:45'),
array('value'=>13, 'label'=>'03:00'),
array('value'=>14, 'label'=>'03:15'),
array('value'=>15, 'label'=>'03:30'),
array('value'=>16, 'label'=>'03:45'),
array('value'=>17, 'label'=>'04:00'),
array('value'=>18, 'label'=>'04:15'),
array('value'=>19, 'label'=>'04:30'),
array('value'=>20, 'label'=>'04:45'),
array('value'=>21, 'label'=>'05:00'),
array('value'=>22, 'label'=>'05:15'),
array('value'=>23, 'label'=>'05:30'),
array('value'=>24, 'label'=>'05:45'),
array('value'=>25, 'label'=>'06:00'),
array('value'=>26, 'label'=>'06:15'),
array('value'=>27, 'label'=>'06:30'),
array('value'=>28, 'label'=>'06:45'),
array('value'=>29, 'label'=>'07:00'),
array('value'=>30, 'label'=>'07:15'),
array('value'=>31, 'label'=>'07:30'),
array('value'=>32, 'label'=>'07:45'),
array('value'=>33, 'label'=>'08:00'),
array('value'=>34, 'label'=>'08:15'),
array('value'=>35, 'label'=>'08:30'),
array('value'=>36, 'label'=>'08:45'),
array('value'=>37, 'label'=>'09:00'),
array('value'=>38, 'label'=>'09:15'),
array('value'=>39, 'label'=>'09:30'),
array('value'=>40, 'label'=>'09:45'),
array('value'=>41, 'label'=>'10:00'),
array('value'=>42, 'label'=>'10:15'),
array('value'=>43, 'label'=>'10:30'),
array('value'=>44, 'label'=>'10:45'),
array('value'=>45, 'label'=>'11:00'),
array('value'=>46, 'label'=>'11:15'),
array('value'=>47, 'label'=>'11:30'),
array('value'=>48, 'label'=>'11:45'),
array('value'=>49, 'label'=>'12:00'),
array('value'=>50, 'label'=>'12:15'),
array('value'=>51, 'label'=>'12:30'),
array('value'=>52, 'label'=>'12:45'),
array('value'=>53, 'label'=>'13:00'),
array('value'=>54, 'label'=>'13:15'),
array('value'=>55, 'label'=>'13:30'),
array('value'=>56, 'label'=>'13:45'),
array('value'=>57, 'label'=>'14:00'),
array('value'=>58, 'label'=>'14:15'),
array('value'=>59, 'label'=>'14:30'),
array('value'=>60, 'label'=>'14:45'),
array('value'=>61, 'label'=>'15:00'),
array('value'=>62, 'label'=>'15:15'),
array('value'=>63, 'label'=>'15:30'),
array('value'=>64, 'label'=>'15:45'),
array('value'=>65, 'label'=>'16:00'),
array('value'=>66, 'label'=>'16:15'),
array('value'=>67, 'label'=>'16:30'),
array('value'=>68, 'label'=>'16:45'),
array('value'=>69, 'label'=>'17:00'),
array('value'=>70, 'label'=>'17:15'),
array('value'=>71, 'label'=>'17:30'),
array('value'=>72, 'label'=>'17:45'),
array('value'=>73, 'label'=>'18:00'),
array('value'=>74, 'label'=>'18:15'),
array('value'=>75, 'label'=>'18:30'),
array('value'=>76, 'label'=>'18:45'),
array('value'=>77, 'label'=>'19:00'),
array('value'=>78, 'label'=>'19:15'),
array('value'=>79, 'label'=>'19:30'),
array('value'=>80, 'label'=>'19:45'),
array('value'=>81, 'label'=>'20:00'),
array('value'=>82, 'label'=>'20:15'),
array('value'=>83, 'label'=>'20:30'),
array('value'=>84, 'label'=>'20:45'),
array('value'=>85, 'label'=>'21:00'),
array('value'=>86, 'label'=>'21:15'),
array('value'=>87, 'label'=>'21:30'),
array('value'=>88, 'label'=>'21:45'),
array('value'=>89, 'label'=>'22:00'),
array('value'=>90, 'label'=>'22:15'),
array('value'=>91, 'label'=>'22:30'),
array('value'=>92, 'label'=>'22:45'),
array('value'=>93, 'label'=>'23:00'),
array('value'=>94, 'label'=>'23:15'),
array('value'=>95, 'label'=>'23:30'),
array('value'=>96, 'label'=>'23:45'),
		
		);
		
		$id= $this->getRequest()->getParam('id');
		$post = Mage::getModel('timetables/post')->load($id);
		
		$array = split(',',$post->getWeekloop());
     	
		$week_array = array(
                    1	=>	'Monday',
		 			2	=> 	'Tuesday',
		 			3 	=>	'Wednesday',
				 	4	=> 	'Thursday',
					5	=> 	'Friday',
					6	=>  'Saturday',
					7	=> 	'Sunday'
        );
	                    
     	if (!empty($array[0]))
     	{
     	    for ($i=0;$i<count($array);$i++)
	     	{
	     		$_value = $array[$i];
	     		$fieldset->addField('starttime'.$_value, 'select', array(
				  'label'     => Mage::helper('timetables')->__($week_array[$_value].' Start Time'),
				  'class'     => 'required-entry',
				  'required'  => true,
				  'name'      => 'starttime'.$_value,
				  'values'    => $time_array,
				));
				
				$fieldset->addField('endtime'.$_value, 'select', array(
				  'label'     => Mage::helper('timetables')->__($week_array[$_value].' End Time'),
				  'class'     => 'required-entry',
				  'required'  => true,
				  'name'      => 'endtime'.$_value,
				 'values'    => $time_array,
				));
	     	}
     	}else{
     		$fieldset->addField('starttime', 'select', array(
				  'label'     => Mage::helper('timetables')->__('Start Time'),
				  'class'     => 'required-entry',
				  'required'  => true,
				  'name'      => 'starttime',
				  'values'    => $time_array,
			));
				
			$fieldset->addField('endtime', 'select', array(
			  'label'     => Mage::helper('timetables')->__('End Time'),
			  'class'     => 'required-entry',
			  'required'  => true,
			  'name'      => 'endtime',
			 'values'    => $time_array,
			));
     	}
		
		$fieldset->addField('data1', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Per Person'),
		  'name'      => 'data1'
		));
		
		$fieldset->addField('data2', 'text', array(
		  'label'     => Mage::helper('timetables')->__('CSP / Leisure Card'),
		  'name'      => 'data2'
		));
		
		$fieldset->addField('data3', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Adult'),
		  'name'      => 'data3'
		));
		
		$fieldset->addField('data4', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Junior'),
		  'name'      => 'data4'
		));
		
		$fieldset->addField('data5', 'text', array(
		  'label'     => Mage::helper('timetables')->__("5's & Under"),
		  'name'      => 'data5'
		));
		
		$fieldset->addField('data6', 'text', array(
		  'label'     => Mage::helper('timetables')->__('Family'),
		  'name'      => 'data6'
		));
		
		$fieldset->addField('data7', 'text', array(
		  'label'     => Mage::helper('timetables')->__("Under 50's"),
		  'name'      => 'data7'
		));
		
		$fieldset->addField('data8', 'text', array(
		  'label'     => Mage::helper('timetables')->__("Over 50's"),
		  'name'      => 'data8'
		));
				
		$fieldset->addField('post_content', 'editor', array(
            'name'      => 'post_content',
            'label'     => Mage::helper('timetables')->__('Content Description'),
            'title'     => Mage::helper('timetables')->__('Content Description'),
            'style'     => 'width:500px; height:200px;',
            'wysiwyg'   => false,
            
        )); 
        
		$form->setFieldNameSuffix('timetables');
		
		if ( Mage::getSingleton('adminhtml/session')->getTimetablesData() )
		{
		  $form->setValues(Mage::getSingleton('adminhtml/session')->getTimetablesData());
		  Mage::getSingleton('adminhtml/session')->setTimetablesData(null);
		} elseif ( Mage::registry('timetables_data') ) {
		  $form->setValues(Mage::registry('timetables_data')->getData());
		}
		return parent::_prepareForm();
  }
}